package progress.exa30_2;

import java.lang.reflect.Field;

public class ReflectionTest {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        Employee harry = new Employee("Harry Hacker");
        Class cl=harry.getClass();
        Field f = cl.getDeclaredField("name");
        //必须有，否则无法访问name的值会出错，作用是将所有域设置成可访问的
        f.setAccessible(true);
        Object v = f.get(harry);
        //输出的是Harry Hacker
        System.out.println(v);
        f.set(harry,"牧之");
        System.out.println(f.get(harry));
    }
}
